<%@ tag pageEncoding="UTF-8" trimDirectiveWhitespaces="true" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://online.view.tag/jsp/jstl/utl" prefix="utl" %>
<%@ taglib uri="http://online.view.tag/jsp/jstl/fnc" prefix="fnc" %>
<%@ attribute name="path" type="java.lang.String" required="false" rtexprvalue="true"%>

<c:set var="pages" value="${fnc:int((fnc:int(gm.Cnt) div fnc:int(gm.Line)))}"/>
<c:set var="last" value="${(gm.Cnt mod gm.Line) eq 0 ? pages : pages + 1}"/>
<c:set var="pre" value="${gm.Page - 1}"/>
<c:set var="post" value="${last - gm.Page}"/>

<c:if test="${last gt 1}">

<c:if test="${empty path}">
	<c:set var="path" value="${gm.ACTION_PATH}"/>
</c:if>

<c:if test="${gm.Page ne 1}">
<utl:param var="prm" name="Page" value="1" />
<a href="${path}?${prm}">1</a>
</c:if>

<c:if test="${(pre ge 4) and (pre + post ge 7)}">
<c:out value="..."/>
</c:if>

<c:if test="${(pre ge 6) and (post eq 0)}">
<utl:param var="prm" name="Page" value="${gm.Page - 5}" />
<a href="${path}?${prm}">${gm.Page - 5}</a>
</c:if>

<c:if test="${(pre ge 5) and (post le 1)}">
<utl:param var="prm" name="Page" value="${gm.Page - 4}" />
<a href="${path}?${prm}">${gm.Page - 4}</a>
</c:if>

<c:if test="${(pre ge 4) and (post le 2)}">
<utl:param var="prm" name="Page" value="${gm.Page - 3}" />
<a href="${path}?${prm}">${gm.Page - 3}</a>
</c:if>

<c:if test="${pre ge 3}">
<utl:param var="prm" name="Page" value="${gm.Page - 2}" />
<a href="${path}?${prm}">${gm.Page - 2}</a>
</c:if>

<c:if test="${pre ge 2}">
<utl:param var="prm" name="Page" value="${gm.Page - 1}" />
<a href="${path}?${prm}">${gm.Page - 1}</a>
</c:if>

${gm.Page}

<c:if test="${post ge 2}">
<utl:param var="prm" name="Page" value="${gm.Page + 1}" />
<a href="${path}?${prm}">${gm.Page + 1}</a>
</c:if>

<c:if test="${post ge 3}">
<utl:param var="prm" name="Page" value="${gm.Page + 2}" />
<a href="${path}?${prm}">${gm.Page + 2}</a>
</c:if>

<c:if test="${(post ge 4) and (pre le 2)}">
<utl:param var="prm" name="Page" value="${gm.Page + 3}" />
<a href="${path}?${prm}">${gm.Page + 3}</a>
</c:if>

<c:if test="${(post ge 5) and (pre le 1)}">
<utl:param var="prm" name="Page" value="${gm.Page + 4}" />
<a href="${path}?${prm}">${gm.Page + 4}</a>
</c:if>

<c:if test="${(post ge 6) and (pre eq 0)}">
<utl:param var="prm" name="Page" value="${gm.Page + 5}" />
<a href="${path}?${prm}">${gm.Page + 5}</a>
</c:if>

<c:if test="${(post ge 4) and (pre + post ge 7)}">
<c:out value="..."/>
</c:if>

<c:if test="${(last ne 1) and (gm.Page ne last)}">
<utl:param var="prm" name="Page" value="${last}" />
<a href="${path}?${prm}">${last}</a>
</c:if>

</c:if>
